4. Wireshark And Nmap

Wireshark is a network protocol (packet) analyzer.It will help us in network troubleshooting,understanding how nmap scans and protocols work.
Common uses of Wireshark:

7963302418de08866288e7b48162bcb7.png

Select your network device interface and press ‘bluefin’ button to see network traffic.
Click on settings(screw) button to get details of your network interface.’Lifelines’ shows there’s traffic flowing through the following interface.

ac5a349ac93669fc6f7e79bea28e1430.png

By default promiscuous mode is enabled meaning wireshark will receive all traffic on the network.Enabling it allows us to view all the packets on the network without limiting to the packets associated with our network adapter.

Filtering packets
If you want to investigate something specific(like a protocol), you can use the Wireshark filter option. A basic method of filtering packets is to use the filter box on the upper section of the tool.For example, if you want to see the results of only DNS traffic, write "dns”.

a6d3d15708b75b12294dd45935915d0b.png


1. Nmap TCP Connect scan

In it we establish a connection with the target by issuing the “connect” system call.But the problem with this scan is that it takes time to complete and it require to generate more packets to obtain information.On the other hand, targets are more likely to allow the connection because it tries to establish a connection with target same as network enabled applications like web browsers.TCP Connect Scan sends a ACK packet and establish the connection.After it establish the connection, it resets the connection.

578aa05f2e75c52e38c13c2e260ff2e8.png

Syntax:

nmap -sT [TARGET] -p [PORT RANGES]

Adding -p option will scan only specified ports.

Metasploitable2 TCP connect scan of ports 1 to 100

d24897498e270ad50acf9c3e152322f7.png

Wireshark Output of the scan

76ac4b54672533c56f6435dd470e099d.png

36361149318eca0ab3bcf5cff535676c.png

Meaning of the default Wireshark colors:

4206ef0c2c3d76162da32fa5dfd6938e.png

Behind the scenes:
Here nmap is completing a TCP Three-Way Handshake.When we connect to each port we are using the TCP Protocol to transmit data between our machine and metasploitable2.

TCP 3-way handshake :

  1. We are using TCP Protocol to send a packet with the SYN flag set =[SYN] (Synchronize Sequence Number).It informs Metasploitable2(Meta2) that we will start communication and the sequence number we start segments with.

  2. Then we get a [SYN, ACK] flag back, it means Meta2 acknowledges that the port is open.
    Acknowledgement(ACK) signifies the response of segment it received and SYN signifies with what sequence number it is likely to start the segments with.

  3. We will send back the [ACK] flag to acknowledge the response of metasploitable2 and we establish a reliable connection.

915c068da3f34d93f2efd5ff87d159f6.png

  1. [RST] is for resetting the connection. It is used when a TCP end detects errors on connection and these errors cannot be recovered from any TCP recovery method ( re transmissions etc) .Here TCP layer reset the connection (terminate the connection) , so that there can be a fresh start.

2. Nmap TCP SYN(stealth) scan
It help us to be little less noisy and covert about our scanning.

Open State:

c3d248487de57c52e48a3111e6e120b3.png

Here we try to establish a connection with target by sending TCP SYN packet. In this situation server sends a SYN/ACK packets to establish the connection.This is the result that Nmap uses to determine whether the port is open. Nmap reset the connection at the end.

Close state:

9e783030bb72bec16fbe15d370d51aaa.png

TCP SYN packet is send to the target as the last time and what happened here is target directly reject the connection with RST packet due to the closed port.

Filtered port:

faf4e6a25303f1943e0922b2f48c241f.png

Target doesn't sends a reply back,not even a RST packet to terminate the connection. Most accurate reason can be a firewall on the target side blocks reply packets. So nmap decides this type of ports as filtered.

8cb2710b450bd2d64b77befc454260db.png

Syntax:

nmap -sS [TARGET] -p [PORT RANGES]

Metasploitable 2 TCP SYN(Stealth) scan of ports 1 to 100

5fa33c5e8ab6b65165a5d6f40ed1fb90.png

In this scan nmap prevent the completing of the TCP 3-way handshake to avoid raising any alarm bells. It first sends the [SYN] flag and receive [SYN, ACK] flag back. After that it sends the [RST]=Reset flag back (highlighted in red) which prematurely terminates the connection.

774446f291dd33ce0e02ac6d5c90f8c6.png

Note: SYN Scan is not stealthy anymore. Widely deployed intrusion detection systems and personal firewalls are quite capable of detecting default SYN scans.